package vn.fpt.fsoft.entities;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;



/**
 * Author:	Thong
 * Entity Address mapping with table Address in database
 * 
 * */
@Entity
@Table(name = "Address")
public class Address implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7762678331632559106L;
	private int addressId;
	private Town town;
	private Integer postcode;
	private Integer countyId;
	private Integer nationId;
	private Set<Organisation> organisations = new HashSet<Organisation>(0);
	private Set<Directorate> directirates = new HashSet<Directorate>(0);
	private Set<Department> departments = new HashSet<Department>(0);
	private Set<Team> teams = new HashSet<Team>(0);

	public Address() {
	}

	public Address(int addressId) {
		this.addressId = addressId;
	}

	public Address(int addressId, Town town, Integer postcode,
			Integer countyId, Integer nationId) {
		this.addressId = addressId;
		this.town = town;
		this.postcode = postcode;
		this.countyId = countyId;
		this.nationId = nationId;
	}
	
	

	/**
	 * @param addressId
	 * @param town
	 * @param postcode
	 * @param countyId
	 * @param nationId
	 * @param organisations
	 * @param directirates
	 * @param departments
	 * @param teams
	 */
	public Address(int addressId, Town town, Integer postcode,
			Integer countyId, Integer nationId,
			Set<Organisation> organisations, Set<Directorate> directirates,
			Set<Department> departments, Set<Team> teams) {
		super();
		this.addressId = addressId;
		this.town = town;
		this.postcode = postcode;
		this.countyId = countyId;
		this.nationId = nationId;
		this.organisations = organisations;
		this.directirates = directirates;
		this.departments = departments;
		this.teams = teams;
	}

	/**
	 * @return the organisations
	 */
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "address")
	public Set<Organisation> getOrganisations() {
		return organisations;
	}

	/**
	 * @param organisations the organisations to set
	 */
	
	public void setOrganisations(Set<Organisation> organisations) {
		this.organisations = organisations;
	}

	/**
	 * @return the directirates
	 */
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "address")
	public Set<Directorate> getDirectirates() {
		return directirates;
	}

	/**
	 * @param directirates the directirates to set
	 */
	
	public void setDirectirates(Set<Directorate> directirates) {
		this.directirates = directirates;
	}

	/**
	 * @return the departments
	 */
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "address")
	public Set<Department> getDepartments() {
		return departments;
	}

	/**
	 * @param departments the departments to set
	 */
	
	public void setDepartments(Set<Department> departments) {
		this.departments = departments;
	}

	/**
	 * @return the teams
	 */
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "address")
	public Set<Team> getTeams() {
		return teams;
	}

	/**
	 * @param teams the teams to set
	 */
	
	public void setTeams(Set<Team> teams) {
		this.teams = teams;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "AddressId")	
	public int getAddressId() {
		return this.addressId;
	}

	public void setAddressId(int addressId) {
		this.addressId = addressId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TownId", nullable = false)
	public Town getTown() {
		return this.town;
	}

	public void setTown(Town town) {
		this.town = town;
	}

	@Column(name = "Postcode")
	public Integer getPostcode() {
		return this.postcode;
	}

	public void setPostcode(Integer postcode) {
		this.postcode = postcode;
	}

	
	@JoinColumn(name = "CountyId")
	public Integer getCountyId() {
		return this.countyId;
	}

	public void setCountyId(Integer countyId) {
		this.countyId = countyId;
	}

	@Column(name = "NationId")
	public Integer getNationId() {
		return this.nationId;
	}

	public void setNationId(Integer nationId) {
		this.nationId = nationId;
	}

}
